<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap1"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <Tsl-price-elec-modal ref="modalForm" @ok="modalFormOk"></Tsl-price-elec-modal>
  </a-card>
</template>

<script>

import '@assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import TslPriceElecModal from './modules/TslPriceElecModal.vue'

export default {
  name: 'TslPriceElecList',
  mixins:[JeecgListMixin, mixinDevice],
  components: {
    TslPriceElecModal
  },
  data() {
    return {
      description: 'Tsl_price_elec管理页面',
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function(t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '名称',
          align: "center",
          customRender: function(text) {
            return "用电"
          }
        },
        {
          title: '适用周期',
          align: "center",
          dataIndex: 'shiyongzhouqikaishi',
          customRender: function(text, record) {
            return !record.cycleStart ? "" : (record.cycleStart.length > 10 ? record.cycleStart.substr(0, 10) : record.cycleStart) + "~" +
              (!record.cycleEnd ? "" : (record.cycleEnd.length > 10 ? record.cycleEnd.substr(0, 10) : record.cycleEnd))
          }
        },
        {
          title: '用能类型',
          align: "center",
          customRender: function(text, record) {
            return "电"
          }
        },
        {
          title: '能源单位',
          align: "center",
          customRender: function(text, record) {
            return "kW·h"
          }
        },
        {
          title: '尖段时间',
          align: "center",
          dataIndex: 'jiankaishi',
          customRender: function(text, record) {
            let res = ""
            for (let i = 0; i < record.highHighCycle.length; i++) {
              res += !record.highHighCycle[i][0] ? "" : (record.highHighCycle[i][0].length > 10 ? record.highHighCycle[i][0].substr(0, 10) : record.highHighCycle[i][0]) + "~" +
                (!record.highHighCycle[i][1] ? "" : (record.highHighCycle[i][1].length > 10 ? record.highHighCycle[i][1].substr(0, 10) : record.highHighCycle[i][1]))
              res += i == record.highHighCycle.length - 1 ? "" : ","
            }
            return res
          }
        },
        {
          title: '尖段价格',
          align: "center",
          dataIndex: 'highHighPrice'
        },
        {
          title: '高段时间',
          align: "center",
          dataIndex: 'gaokaishi',
          customRender: function(text, record) {
            let res = ""
            for (let i = 0; i < record.highCycle.length; i++) {
              res += !record.highCycle[i][0] ? "" : (record.highCycle[i][0].length > 10 ? record.highCycle[i][0].substr(0, 10) : record.highCycle[i][0]) + "~" +
                (!record.highCycle[i][1] ? "" : (record.highCycle[i][1].length > 10 ? record.highCycle[i][1].substr(0, 10) : record.highCycle[i][1]))
              res += i == record.highCycle.length - 1 ? "" : ","
            }
            return res
          }
        },
        {
          title: '高段价格',
          align: "center",
          dataIndex: 'highPrice'
        },
        {
          title: '平段时间',
          align: "center",
          dataIndex: 'pingkaishi',
          customRender: function(text, record) {
            let res = ""
            for (let i = 0; i < record.flatCycle.length; i++) {
              res += !record.flatCycle[i][0] ? "" : (record.flatCycle[i][0].length > 10 ? record.flatCycle[i][0].substr(0, 10) : record.flatCycle[i][0]) + "~" +
                (!record.flatCycle[i][1] ? "" : (record.flatCycle[i][1].length > 10 ? record.flatCycle[i][1].substr(0, 10) : record.flatCycle[i][1]))
              res += i == record.flatCycle.length - 1 ? "" : ","
            }
            return res
          }
        },
        {
          title: '平段价格',
          align: "center",
          dataIndex: 'flatPrice'
        },
        {
          title: '谷段时间',
          align: "center",
          dataIndex: 'gukaishi',
          customRender: function(text, record) {
            let res = ""
            for (let i = 0; i < record.lowCycle.length; i++) {
              res += !record.lowCycle[i][0] ? "" : (record.lowCycle[i][0].length > 10 ? record.lowCycle[i][0].substr(0, 10) : record.lowCycle[i][0]) + "~" +
                (!record.lowCycle[i][1] ? "" : (record.lowCycle[i][1].length > 10 ? record.lowCycle[i][1].substr(0, 10) : record.lowCycle[i][1]))
              res += i == record.lowCycle.length - 1 ? "" : ","
            }
            return res
          }
        },
        {
          title: '谷段价格',
          align: "center",
          dataIndex: 'lowPrice'
        },
        {
          title: '单位',
          align: "center",
          customRender: function(text, record) {
            return "元/kW·h"
          }
        },
        {
          title: '维护人',
          align: "center",
          dataIndex: 'createBy',
          customRender: function(text, record) {
            return record.updateBy?record.updateBy:record.createBy
          }
        },
        {
          title: '维护时间',
          align: 'center',
          customRender: function(text,record) {
            return !record.updateTime ? record.createTime : record.updateTime
          }
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          fixed: "right",
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: "/energy/tslPriceElec/list",
        delete: "/energy/tslPriceElec/delete",
        deleteBatch: "/energy/tslPriceElec/deleteBatch",
        exportXlsUrl: "/energy/tslPriceElec/exportXls",
        importExcelUrl: "energy/tslPriceElec/importExcel",

      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList();
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: 'date', value: 'cycleStart', text: '适用周期开始' })
      fieldList.push({ type: 'date', value: 'cycleEnd', text: '适用周期结束' })
      fieldList.push({ type: 'string', value: 'highHighCycle', text: 'highHighCycle' })
      fieldList.push({ type: 'number', value: 'highHighPrice', text: '尖段价格' })
      fieldList.push({ type: 'string', value: 'highCycle', text: 'highCycle' })
      fieldList.push({ type: 'number', value: 'highPrice', text: '高段价格' })
      fieldList.push({ type: 'string', value: 'flatCycle', text: 'flatCycle' })
      fieldList.push({ type: 'number', value: 'flatPrice', text: '平段价格' })
      fieldList.push({ type: 'string', value: 'lowCycle', text: 'lowCycle' })
      fieldList.push({ type: 'number', value: 'lowPrice', text: '谷段价格' })
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>